
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>SQL常用使用 · JAVA学习积累</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="tianwyam">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-pageview-count/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../redis/redis_study_notes.html" />
    
    
    <link rel="prev" href="../distributed/sharding-jdbc.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="https://blog.csdn.net/mybook201314" target="_blank" class="custom-link">博客Blog</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        <li class="header">【前言】</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    介绍ABOUT
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第一章】Java基础</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../java/java.html">
            
                <a href="../java/java.html">
            
                    
                    计算机基础-操作系统-进程-计算机网络
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="../java/java_thread_pool.html">
            
                <a href="../java/java_thread_pool.html">
            
                    
                    线程池的工作原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="../java/java_ftp.html">
            
                <a href="../java/java_ftp.html">
            
                    
                    FTP文件服务器上传下载
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="../java/collection.html">
            
                <a href="../java/collection.html">
            
                    
                    集合
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.4.1" data-path="../java/collection/java_collection_map.html">
            
                <a href="../java/collection/java_collection_map.html">
            
                    
                    Map&HashMap&HashTable&ConcurrentHashMap
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.2" data-path="../java/java_queue.html">
            
                <a href="../java/java_queue.html">
            
                    
                    队列-queue
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.3" data-path="../java/java_tree.html">
            
                <a href="../java/java_tree.html">
            
                    
                    二叉树遍历
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../java/java_io_nio.html">
            
                <a href="../java/java_io_nio.html">
            
                    
                    java输入输出流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="../java/java_exception.html">
            
                <a href="../java/java_exception.html">
            
                    
                    异常exception
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="../java/java_serialize.html">
            
                <a href="../java/java_serialize.html">
            
                    
                    Java序列化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="../java/Java_annotation.html">
            
                <a href="../java/Java_annotation.html">
            
                    
                    注解
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="../java/multi.html">
            
                <a href="../java/multi.html">
            
                    
                    多线程
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1.1" data-path="../java/multithread/java_multi_thread_volatile_synchronized.html">
            
                <a href="../java/multithread/java_multi_thread_volatile_synchronized.html">
            
                    
                    volatile&synchronized
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.2" data-path="../java/multithread/java_multi_thread_object_wait_notify.html">
            
                <a href="../java/multithread/java_multi_thread_object_wait_notify.html">
            
                    
                    object/wait/notify
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.3" data-path="../java/multithread/java_multi_thread_thread.html">
            
                <a href="../java/multithread/java_multi_thread_thread.html">
            
                    
                    thread
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.4" data-path="../java/multithread/java_multi_thread_threadpool.html">
            
                <a href="../java/multithread/java_multi_thread_threadpool.html">
            
                    
                    线程池的工作原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.5" data-path="../java/multithread/java_multi_thread_lock.html">
            
                <a href="../java/multithread/java_multi_thread_lock.html">
            
                    
                    lock&ReentrantLock&ReadWriteLock
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.6" data-path="../java/multithread/java_multi_thread_lock_condition.html">
            
                <a href="../java/multithread/java_multi_thread_lock_condition.html">
            
                    
                    lock&condition
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.7" data-path="../java/multithread/java_multi_thread_tools.html">
            
                <a href="../java/multithread/java_multi_thread_tools.html">
            
                    
                    Java并发工具- CountDownLatch&CyclicBarrier 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.8" data-path="../java/multithread/java_multi_thread_tools2.html">
            
                <a href="../java/multithread/java_multi_thread_tools2.html">
            
                    
                    Java同步工具类- CountDownLatch&CyclicBarrier&Semaphore  
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="../java/java_jvm.html">
            
                <a href="../java/java_jvm.html">
            
                    
                    java虚拟机-JVM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="../java/java_java7new.html">
            
                <a href="../java/java_java7new.html">
            
                    
                    java7新知识- Switch&TWR&Objects 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="../java/java_stream.html">
            
                <a href="../java/java_stream.html">
            
                    
                    Java8对集合流操作stream
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="../java/java_stream_groupby.html">
            
                <a href="../java/java_stream_groupby.html">
            
                    
                    java8新语法-Stream-分组groupingBy操作 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="../java/java_optional.html">
            
                <a href="../java/java_optional.html">
            
                    
                    java8新语法-Optional 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="../java/java_8new_date_api.html">
            
                <a href="../java/java_8new_date_api.html">
            
                    
                    java8-新的日期时间API 
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="6.1" data-path="../xml/xml_translation.html">
            
                <a href="../xml/xml_translation.html">
            
                    
                    XML中特殊符号的转译 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="../datastructure/binary_complement.html">
            
                <a href="../datastructure/binary_complement.html">
            
                    
                    原码、反码、补码 
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="7.1" data-path="../java/basic/javabean2map.html">
            
                <a href="../java/basic/javabean2map.html">
            
                    
                    Java bean转Map 
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第二章】算法积累题</li>
        
        
    
        <li class="chapter " data-level="8.1" data-path="../algorithm/merge_sorted_array.html">
            
                <a href="../algorithm/merge_sorted_array.html">
            
                    
                    算法题 - 合并排序数组 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="8.2" data-path="../algorithm/lowest_score.html">
            
                <a href="../algorithm/lowest_score.html">
            
                    
                    算法题 - 最低分数线问题 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="8.3" data-path="../algorithm/array_sub_list.html">
            
                <a href="../algorithm/array_sub_list.html">
            
                    
                    算法题 - 求数组的子集合 
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第三章】框架</li>
        
        
    
        <li class="chapter " data-level="9.1" data-path="../Spring/springboot.html">
            
                <a href="../Spring/springboot.html">
            
                    
                    SpringBoot
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="9.2" data-path="../Spring/spring_security.html">
            
                <a href="../Spring/spring_security.html">
            
                    
                    SpringSecurity
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="9.3" data-path="../linux/linux_commands_springboot_startup.html">
            
                <a href="../linux/linux_commands_springboot_startup.html">
            
                    
                    SpringBoot项目启动脚本
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="10.1" data-path="../Spring/spring/spring_interview_questions_68.html">
            
                <a href="../Spring/spring/spring_interview_questions_68.html">
            
                    
                    Spring面试题68
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="11.1" data-path="../Spring/springboot_auto_config.html">
            
                <a href="../Spring/springboot_auto_config.html">
            
                    
                    SpringBoot自动装载机制 - 源码分析
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="12.1" data-path="../Spring/spring_feign.html">
            
                <a href="../Spring/spring_feign.html">
            
                    
                    Feign在spring、springboot下使用
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="13.1" data-path="../Spring/spring_freemarker.html">
            
                <a href="../Spring/spring_freemarker.html">
            
                    
                    Spring boot集成freemarker，生成word文件
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="14.1" data-path="../Spring/spring_freemarker_generate.html">
            
                <a href="../Spring/spring_freemarker_generate.html">
            
                    
                    Freemarker自动生成Java bean代码
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="15.1" data-path="../mybatis/mybatis_metadata.html">
            
                <a href="../mybatis/mybatis_metadata.html">
            
                    
                    mybatis中操作元数据
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="15.2" data-path="../mybatis/mybatis_batch_exec_sql.html">
            
                <a href="../mybatis/mybatis_batch_exec_sql.html">
            
                    
                    mybatis中insert/update/delete标签中执行多条SQL语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="15.3" data-path="../mybatis/mybatis_plus.html">
            
                <a href="../mybatis/mybatis_plus.html">
            
                    
                    springboot集成mybatis-plus框架
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="16.1" data-path="../distributed/sharding-jdbc.html">
            
                <a href="../distributed/sharding-jdbc.html">
            
                    
                    【分布式】sharding-jdbc实现分库分表
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第四章】数据库</li>
        
        
    
        <li class="chapter active" data-level="17.1" data-path="sql.html">
            
                <a href="sql.html">
            
                    
                    SQL常用使用
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="18.1" data-path="../redis/redis_study_notes.html">
            
                <a href="../redis/redis_study_notes.html">
            
                    
                    redis学习笔记
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="18.2" data-path="../redis/redis_list_second_kill.html">
            
                <a href="../redis/redis_list_second_kill.html">
            
                    
                    Redis中的队列list实现秒杀活动抢购
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="19.1" data-path="sql_mysql_green_install.html">
            
                <a href="sql_mysql_green_install.html">
            
                    
                    mysql绿色版安装服务教程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="19.2" data-path="sql_h2.html">
            
                <a href="sql_h2.html">
            
                    
                    H2内嵌数据的使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="19.3" data-path="cache.html">
            
                <a href="cache.html">
            
                    
                    缓存
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="19.4" data-path="mysql/mysql_back_rollback.html">
            
                <a href="mysql/mysql_back_rollback.html">
            
                    
                    MySQL单表备份还原
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第五章】Web</li>
        
        
    
        <li class="chapter " data-level="20.1" data-path="../web/web_js_jquery.html">
            
                <a href="../web/web_js_jquery.html">
            
                    
                    web简单积累
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第六章】Linux</li>
        
        
    
        <li class="chapter " data-level="21.1" data-path="../linux/linux_common_commands.html">
            
                <a href="../linux/linux_common_commands.html">
            
                    
                    linux常用命令
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第七章】Windows</li>
        
        
    
        <li class="chapter " data-level="22.1" data-path="../windows/windows_common_commands.html">
            
                <a href="../windows/windows_common_commands.html">
            
                    
                    windows常用命令
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第八章】错误集</li>
        
        
    
        <li class="chapter " data-level="23.1" data-path="../error/maven_not_found_local_jar.html">
            
                <a href="../error/maven_not_found_local_jar.html">
            
                    
                    maven引入依赖时识别不到本地仓库的jar
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="24.1" data-path="../error/security_not_configure_antMatchers_after_anyRequest.html">
            
                <a href="../error/security_not_configure_antMatchers_after_anyRequest.html">
            
                    
                    spring security 配置发生错误 Can't configure antMatchers after anyRequest
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="25.1" data-path="../error/AOP_stream_close_error.html">
            
                <a href="../error/AOP_stream_close_error.html">
            
                    
                    AOP内获取了对请求流操作后报流已经关闭错误的问题
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="26.1" data-path="../tools/github/github_ssh.html">
            
                <a href="../tools/github/github_ssh.html">
            
                    
                    Github ssh key 解决提交后push频繁输入用户名和密码
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="27.1" data-path="../error/sharding-jdbc-error-datasources.html">
            
                <a href="../error/sharding-jdbc-error-datasources.html">
            
                    
                    sharding-jdbc-4.1.1版本启动数据源报错问题
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >SQL常用使用</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#sql"><b></b>SQL</a></li><li><span class="title-icon "></span><a href="#1&#x3001;&#x5E38;&#x7528;&#x7684;sql&#x547D;&#x4EE4;"><b></b>1&#x3001;&#x5E38;&#x7528;&#x7684;SQL&#x547D;&#x4EE4;</a></li><ul><li><span class="title-icon "></span><a href="#11&#x3001;&#x5207;&#x6362;&#x6570;&#x636E;&#x5E93;"><b></b>1.1&#x3001;&#x5207;&#x6362;&#x6570;&#x636E;&#x5E93;</a></li><li><span class="title-icon "></span><a href="#12&#x3001;&#x67E5;&#x770B;&#x6570;&#x636E;&#x5E93;&#x4E0B;&#x7684;&#x8868;"><b></b>1.2&#x3001;&#x67E5;&#x770B;&#x6570;&#x636E;&#x5E93;&#x4E0B;&#x7684;&#x8868;</a></li><li><span class="title-icon "></span><a href="#13&#x3001;&#x67E5;&#x770B;&#x8868;&#x4FE1;&#x606F;"><b></b>1.3&#x3001;&#x67E5;&#x770B;&#x8868;&#x4FE1;&#x606F;</a></li><li><span class="title-icon "></span><a href="#14&#x3001;&#x67E5;&#x770B;&#x521B;&#x5EFA;&#x8868;&#x65F6;&#x7684;&#x521B;&#x5EFA;&#x4FE1;&#x606F;"><b></b>1.4&#x3001;&#x67E5;&#x770B;&#x521B;&#x5EFA;&#x8868;&#x65F6;&#x7684;&#x521B;&#x5EFA;&#x4FE1;&#x606F;</a></li><li><span class="title-icon "></span><a href="#15&#x3001;&#x4FEE;&#x6539;&#x8868;&#x540D;"><b></b>1.5&#x3001;&#x4FEE;&#x6539;&#x8868;&#x540D;</a></li><li><span class="title-icon "></span><a href="#16&#x3001;&#x5220;&#x9664;&#x8868;"><b></b>1.6&#x3001;&#x5220;&#x9664;&#x8868;</a></li><li><span class="title-icon "></span><a href="#17&#x3001;&#x589E;&#x52A0;&#x5B57;&#x6BB5;"><b></b>1.7&#x3001;&#x589E;&#x52A0;&#x5B57;&#x6BB5;</a></li><li><span class="title-icon "></span><a href="#18&#x3001;&#x5220;&#x9664;&#x5B57;&#x6BB5;"><b></b>1.8&#x3001;&#x5220;&#x9664;&#x5B57;&#x6BB5;</a></li><li><span class="title-icon "></span><a href="#19&#x3001;&#x4FEE;&#x6539;&#x5B57;&#x6BB5;"><b></b>1.9&#x3001;&#x4FEE;&#x6539;&#x5B57;&#x6BB5;</a></li><li><span class="title-icon "></span><a href="#110&#x3001;&#x5173;&#x8054;&#x66F4;&#x65B0;"><b></b>1.10&#x3001;&#x5173;&#x8054;&#x66F4;&#x65B0;</a></li></ul><li><span class="title-icon "></span><a href="#2&#x3001;&#x9AD8;&#x7EA7;&#x547D;&#x4EE4;"><b></b>2&#x3001;&#x9AD8;&#x7EA7;&#x547D;&#x4EE4;</a></li><ul><li><span class="title-icon "></span><a href="#21&#x3001;&#x4FEE;&#x6539;&#x65F6;&#x95F4;&#x7C7B;&#x578B;&#x7684;&#x9ED8;&#x8BA4;&#x503C;"><b></b>2.1&#x3001;&#x4FEE;&#x6539;&#x65F6;&#x95F4;&#x7C7B;&#x578B;&#x7684;&#x9ED8;&#x8BA4;&#x503C;</a></li><li><span class="title-icon "></span><a href="#22&#x3001;&#x4FEE;&#x6539;&#x81EA;&#x589E;&#x5E8F;&#x5217;&#x7684;&#x521D;&#x59CB;&#x503C;"><b></b>2.2&#x3001;&#x4FEE;&#x6539;&#x81EA;&#x589E;&#x5E8F;&#x5217;&#x7684;&#x521D;&#x59CB;&#x503C;</a></li><li><span class="title-icon "></span><a href="#23&#x3001;&#x540C;&#x65F6;&#x5220;&#x9664;&#x4E24;&#x5F20;&#x8868;"><b></b>2.3&#x3001;&#x540C;&#x65F6;&#x5220;&#x9664;&#x4E24;&#x5F20;&#x8868;</a></li><li><span class="title-icon "></span><a href="#24&#x3001;&#x540C;&#x65F6;&#x66F4;&#x65B0;&#x4E24;&#x5F20;&#x8868;"><b></b>2.4&#x3001;&#x540C;&#x65F6;&#x66F4;&#x65B0;&#x4E24;&#x5F20;&#x8868;</a></li><li><span class="title-icon "></span><a href="#25&#x3001;sql&#x4E2D;&#x7684;&#x4E09;&#x76EE;&#x8FD0;&#x7B97;&#x7B26;"><b></b>2.5&#x3001;SQL&#x4E2D;&#x7684;&#x4E09;&#x76EE;&#x8FD0;&#x7B97;&#x7B26;</a></li></ul><li><span class="title-icon "></span><a href="#3&#x3001;&#x5E8F;&#x5217;"><b></b>3&#x3001;&#x5E8F;&#x5217;</a></li></ul></div><h1 id="sql"><a name="sql" class="anchor-navigation-ex-anchor" href="#sql"><i class="fa fa-link" aria-hidden="true"></i></a>SQL</h1>
<h1 id="1&#x3001;&#x5E38;&#x7528;&#x7684;sql&#x547D;&#x4EE4;"><a name="1&#x3001;&#x5E38;&#x7528;&#x7684;sql&#x547D;&#x4EE4;" class="anchor-navigation-ex-anchor" href="#1&#x3001;&#x5E38;&#x7528;&#x7684;sql&#x547D;&#x4EE4;"><i class="fa fa-link" aria-hidden="true"></i></a>1&#x3001;&#x5E38;&#x7528;&#x7684;SQL&#x547D;&#x4EE4;</h1>
<h2 id="11&#x3001;&#x5207;&#x6362;&#x6570;&#x636E;&#x5E93;"><a name="11&#x3001;&#x5207;&#x6362;&#x6570;&#x636E;&#x5E93;" class="anchor-navigation-ex-anchor" href="#11&#x3001;&#x5207;&#x6362;&#x6570;&#x636E;&#x5E93;"><i class="fa fa-link" aria-hidden="true"></i></a>1.1&#x3001;&#x5207;&#x6362;&#x6570;&#x636E;&#x5E93;</h2>
<pre><code class="lang-sql">
<span class="hljs-comment">-- test &#x662F;&#x6570;&#x636E;&#x5E93;&#x540D;</span>
<span class="hljs-keyword">use</span> <span class="hljs-keyword">test</span>;
</code></pre>
<h2 id="12&#x3001;&#x67E5;&#x770B;&#x6570;&#x636E;&#x5E93;&#x4E0B;&#x7684;&#x8868;"><a name="12&#x3001;&#x67E5;&#x770B;&#x6570;&#x636E;&#x5E93;&#x4E0B;&#x7684;&#x8868;" class="anchor-navigation-ex-anchor" href="#12&#x3001;&#x67E5;&#x770B;&#x6570;&#x636E;&#x5E93;&#x4E0B;&#x7684;&#x8868;"><i class="fa fa-link" aria-hidden="true"></i></a>1.2&#x3001;&#x67E5;&#x770B;&#x6570;&#x636E;&#x5E93;&#x4E0B;&#x7684;&#x8868;</h2>
<pre><code class="lang-sql">
<span class="hljs-keyword">show</span> <span class="hljs-keyword">tables</span>;
</code></pre>
<p>&#x8F93;&#x51FA;&#x663E;&#x793A;&#xFF1A;&#x5F53;&#x524D;&#x6570;&#x636E;&#x5E93;&#x4E0B;&#x7684;&#x6240;&#x6709;&#x8868;&#x540D;</p>
<h2 id="13&#x3001;&#x67E5;&#x770B;&#x8868;&#x4FE1;&#x606F;"><a name="13&#x3001;&#x67E5;&#x770B;&#x8868;&#x4FE1;&#x606F;" class="anchor-navigation-ex-anchor" href="#13&#x3001;&#x67E5;&#x770B;&#x8868;&#x4FE1;&#x606F;"><i class="fa fa-link" aria-hidden="true"></i></a>1.3&#x3001;&#x67E5;&#x770B;&#x8868;&#x4FE1;&#x606F;</h2>
<pre><code class="lang-sql">
<span class="hljs-comment">-- user &#x662F;&#x8868;&#x540D;</span>
desc user ;
</code></pre>
<p>&#x5C06;&#x663E;&#x793A;&#x8F93;&#x51FA;&#xFF1A;&#x8868;&#x5B57;&#x6BB5;&#x7684;&#x63CF;&#x8FF0;&#x4FE1;&#x606F;</p>
<h2 id="14&#x3001;&#x67E5;&#x770B;&#x521B;&#x5EFA;&#x8868;&#x65F6;&#x7684;&#x521B;&#x5EFA;&#x4FE1;&#x606F;"><a name="14&#x3001;&#x67E5;&#x770B;&#x521B;&#x5EFA;&#x8868;&#x65F6;&#x7684;&#x521B;&#x5EFA;&#x4FE1;&#x606F;" class="anchor-navigation-ex-anchor" href="#14&#x3001;&#x67E5;&#x770B;&#x521B;&#x5EFA;&#x8868;&#x65F6;&#x7684;&#x521B;&#x5EFA;&#x4FE1;&#x606F;"><i class="fa fa-link" aria-hidden="true"></i></a>1.4&#x3001;&#x67E5;&#x770B;&#x521B;&#x5EFA;&#x8868;&#x65F6;&#x7684;&#x521B;&#x5EFA;&#x4FE1;&#x606F;</h2>
<pre><code class="lang-sql">
<span class="hljs-comment">-- user &#x662F;&#x8868;&#x540D;</span>
<span class="hljs-keyword">show</span> <span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-keyword">user</span>;
</code></pre>
<p>&#x5C06;&#x8F93;&#x51FA;&#x663E;&#x793A;&#xFF1A;&#x521B;&#x5EFA;&#x8868;&#x65F6;&#x7684;&#x521B;&#x5EFA;&#x8BED;&#x53E5;</p>
<h2 id="15&#x3001;&#x4FEE;&#x6539;&#x8868;&#x540D;"><a name="15&#x3001;&#x4FEE;&#x6539;&#x8868;&#x540D;" class="anchor-navigation-ex-anchor" href="#15&#x3001;&#x4FEE;&#x6539;&#x8868;&#x540D;"><i class="fa fa-link" aria-hidden="true"></i></a>1.5&#x3001;&#x4FEE;&#x6539;&#x8868;&#x540D;</h2>
<pre><code class="lang-sql">
<span class="hljs-comment">-- user &#x662F;&#x539F;&#x8868;&#x540D;&#xFF0C;users &#x662F;&#x4FEE;&#x6539;&#x540E;&#x7684;&#x8868;&#x540D;</span>
<span class="hljs-keyword">alter</span> <span class="hljs-keyword">table</span> <span class="hljs-keyword">user</span> <span class="hljs-keyword">RENAME</span> <span class="hljs-keyword">users</span>;
</code></pre>
<h2 id="16&#x3001;&#x5220;&#x9664;&#x8868;"><a name="16&#x3001;&#x5220;&#x9664;&#x8868;" class="anchor-navigation-ex-anchor" href="#16&#x3001;&#x5220;&#x9664;&#x8868;"><i class="fa fa-link" aria-hidden="true"></i></a>1.6&#x3001;&#x5220;&#x9664;&#x8868;</h2>
<pre><code class="lang-sql">
<span class="hljs-comment">-- user&#x662F;&#x8981;&#x5220;&#x9664;&#x7684;&#x8868;&#x540D;</span>
<span class="hljs-keyword">DROP</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-keyword">IF</span> <span class="hljs-keyword">EXISTS</span> <span class="hljs-keyword">user</span>;
</code></pre>
<p>&#x6CE8;&#xFF1A;&#x5220;&#x9664;&#x8868;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;drop table&#x3002;&#x5220;&#x9664;&#x591A;&#x4E2A;&#x8868;&#x65F6;&#xFF0C;&#x8868;&#x4E4B;&#x95F4;&#x7528;&#x9017;&#x53F7;&#x5206;&#x9694;&#x3002;IF EXISTS&#x7528;&#x6765;&#x5728;&#x5220;&#x8868;&#x4E4B;&#x524D;&#x5224;&#x65AD;&#x8868;&#x662F;&#x5426;&#x5B58;&#x5728;&#xFF0C;&#x53EF;&#x907F;&#x514D;&#x62A5;&#x9519;&#x3002;</p>
<p>&#x5982;&#xFF1A;</p>
<pre><code class="lang-sql"><span class="hljs-keyword">DROP</span> <span class="hljs-keyword">TABLE</span> [<span class="hljs-keyword">IF</span> <span class="hljs-keyword">EXISTS</span>] table1 [,table2]...
</code></pre>
<h2 id="17&#x3001;&#x589E;&#x52A0;&#x5B57;&#x6BB5;"><a name="17&#x3001;&#x589E;&#x52A0;&#x5B57;&#x6BB5;" class="anchor-navigation-ex-anchor" href="#17&#x3001;&#x589E;&#x52A0;&#x5B57;&#x6BB5;"><i class="fa fa-link" aria-hidden="true"></i></a>1.7&#x3001;&#x589E;&#x52A0;&#x5B57;&#x6BB5;</h2>
<pre><code class="lang-sql">
<span class="hljs-comment">/* user &#x662F;&#x8868;&#x540D;&#xFF0C;
usertype &#x662F;&#x8981;&#x589E;&#x52A0;&#x7684;&#x5217;&#x540D;&#xFF0C;
&#x7C7B;&#x578B;int&#xFF0C;&#x957F;&#x5EA6; 1&#xFF0C;&#x975E;&#x7A7A;&#xFF0C;&#x9ED8;&#x8BA4;&#x503C;&#x4E3A; 0 */</span>
<span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-keyword">user</span> 
<span class="hljs-keyword">ADD</span> <span class="hljs-keyword">COLUMN</span> usertype <span class="hljs-built_in">INT</span>(<span class="hljs-number">1</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-number">0</span>
</code></pre>
<h2 id="18&#x3001;&#x5220;&#x9664;&#x5B57;&#x6BB5;"><a name="18&#x3001;&#x5220;&#x9664;&#x5B57;&#x6BB5;" class="anchor-navigation-ex-anchor" href="#18&#x3001;&#x5220;&#x9664;&#x5B57;&#x6BB5;"><i class="fa fa-link" aria-hidden="true"></i></a>1.8&#x3001;&#x5220;&#x9664;&#x5B57;&#x6BB5;</h2>
<pre><code class="lang-sql">
<span class="hljs-comment">-- user &#x662F;&#x8868;&#x540D;&#xFF0C;usertype &#x662F;&#x8981;&#x5220;&#x9664;&#x7684;&#x5B57;&#x6BB5;&#x540D;</span>
<span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-keyword">user</span> <span class="hljs-keyword">DROP</span> <span class="hljs-keyword">COLUMN</span> usertype
</code></pre>
<h2 id="19&#x3001;&#x4FEE;&#x6539;&#x5B57;&#x6BB5;"><a name="19&#x3001;&#x4FEE;&#x6539;&#x5B57;&#x6BB5;" class="anchor-navigation-ex-anchor" href="#19&#x3001;&#x4FEE;&#x6539;&#x5B57;&#x6BB5;"><i class="fa fa-link" aria-hidden="true"></i></a>1.9&#x3001;&#x4FEE;&#x6539;&#x5B57;&#x6BB5;</h2>
<p>1&#x3001;&#x4FEE;&#x6539;&#x5B57;&#x6BB5;&#x7C7B;&#x578B;</p>
<pre><code class="lang-sql">
<span class="hljs-comment">/* user &#x662F;&#x8868;&#x540D;&#xFF0C;
usertype &#x662F;&#x5B57;&#x6BB5;&#x540D;&#xFF0C;
&#x4FEE;&#x6539;&#x5B57;&#x6BB5;&#x7C7B;&#x578B;&#x4E3A; varchar &#x957F;&#x5EA6;&#x4E3A; 1 */</span>
<span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-keyword">user</span> <span class="hljs-keyword">MODIFY</span> usertype <span class="hljs-built_in">VARCHAR</span>(<span class="hljs-number">1</span>);
</code></pre>
<p>2&#x3001;&#x4FEE;&#x6539;&#x5B57;&#x6BB5;&#x540D;</p>
<pre><code class="lang-sql">
<span class="hljs-comment">/* user&#x662F;&#x8868;&#x540D;&#xFF0C;
usetype &#x662F; old_column_name , 
isadmin &#x662F; new_column_name,&#x65B0;&#x7684;&#x5217;&#x7C7B;&#x578B;&#x662F;int,&#x957F;&#x5EA6;&#x4E3A; 1 */</span>
<span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-keyword">user</span> <span class="hljs-keyword">CHANGE</span> usetype isadmin <span class="hljs-built_in">INT</span>(<span class="hljs-number">1</span>);
</code></pre>
<p>&#x6CE8;&#xFF1A;&#x4FEE;&#x6539;&#x5B57;&#x6BB5;&#x540D;&#x65F6;&#x4E00;&#x5B9A;&#x8981;&#x91CD;&#x65B0;&#x6307;&#x5B9A;&#x8BE5;&#x5B57;&#x6BB5;&#x7C7B;&#x578B;</p>
<h2 id="110&#x3001;&#x5173;&#x8054;&#x66F4;&#x65B0;"><a name="110&#x3001;&#x5173;&#x8054;&#x66F4;&#x65B0;" class="anchor-navigation-ex-anchor" href="#110&#x3001;&#x5173;&#x8054;&#x66F4;&#x65B0;"><i class="fa fa-link" aria-hidden="true"></i></a>1.10&#x3001;&#x5173;&#x8054;&#x66F4;&#x65B0;</h2>
<pre><code class="lang-sql"><span class="hljs-comment">-- &#x5F53;&#x9700;&#x8981;&#x66F4;&#x65B0;&#x7684;&#x503C;&#x662F;&#x53E6;&#x4E00;&#x4E2A;&#x8868;&#x5173;&#x8054;&#x7684;&#x503C;&#x7684;&#x65F6;&#x5019;&#x4F7F;&#x7528;</span>

<span class="hljs-keyword">update</span> user_info
<span class="hljs-keyword">set</span> age = p.age
<span class="hljs-keyword">from</span> user_info_param p
<span class="hljs-keyword">where</span> user_id = p.user_id
</code></pre>
<hr>
<p> &#x3000;</p>
<h1 id="2&#x3001;&#x9AD8;&#x7EA7;&#x547D;&#x4EE4;"><a name="2&#x3001;&#x9AD8;&#x7EA7;&#x547D;&#x4EE4;" class="anchor-navigation-ex-anchor" href="#2&#x3001;&#x9AD8;&#x7EA7;&#x547D;&#x4EE4;"><i class="fa fa-link" aria-hidden="true"></i></a>2&#x3001;&#x9AD8;&#x7EA7;&#x547D;&#x4EE4;</h1>
<h2 id="21&#x3001;&#x4FEE;&#x6539;&#x65F6;&#x95F4;&#x7C7B;&#x578B;&#x7684;&#x9ED8;&#x8BA4;&#x503C;"><a name="21&#x3001;&#x4FEE;&#x6539;&#x65F6;&#x95F4;&#x7C7B;&#x578B;&#x7684;&#x9ED8;&#x8BA4;&#x503C;" class="anchor-navigation-ex-anchor" href="#21&#x3001;&#x4FEE;&#x6539;&#x65F6;&#x95F4;&#x7C7B;&#x578B;&#x7684;&#x9ED8;&#x8BA4;&#x503C;"><i class="fa fa-link" aria-hidden="true"></i></a>2.1&#x3001;&#x4FEE;&#x6539;&#x65F6;&#x95F4;&#x7C7B;&#x578B;&#x7684;&#x9ED8;&#x8BA4;&#x503C;</h2>
<pre><code class="lang-sql">
<span class="hljs-comment">--&#x4FEE;&#x6539;CreateTime &#x8BBE;&#x7F6E;&#x9ED8;&#x8BA4;&#x65F6;&#x95F4; = CURRENT_TIMESTAMP &#x5F53;&#x524D;&#x65F6;&#x95F4;</span>

<span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> tableName 
<span class="hljs-keyword">MODIFY</span> <span class="hljs-keyword">COLUMN</span> CreateTime DATETIME <span class="hljs-literal">NULL</span> 
<span class="hljs-keyword">DEFAULT</span> <span class="hljs-keyword">CURRENT_TIMESTAMP</span> 
<span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x521B;&#x5EFA;&#x65F6;&#x95F4;&apos;</span> ;
</code></pre>
<h2 id="22&#x3001;&#x4FEE;&#x6539;&#x81EA;&#x589E;&#x5E8F;&#x5217;&#x7684;&#x521D;&#x59CB;&#x503C;"><a name="22&#x3001;&#x4FEE;&#x6539;&#x81EA;&#x589E;&#x5E8F;&#x5217;&#x7684;&#x521D;&#x59CB;&#x503C;" class="anchor-navigation-ex-anchor" href="#22&#x3001;&#x4FEE;&#x6539;&#x81EA;&#x589E;&#x5E8F;&#x5217;&#x7684;&#x521D;&#x59CB;&#x503C;"><i class="fa fa-link" aria-hidden="true"></i></a>2.2&#x3001;&#x4FEE;&#x6539;&#x81EA;&#x589E;&#x5E8F;&#x5217;&#x7684;&#x521D;&#x59CB;&#x503C;</h2>
<pre><code class="lang-sql">
<span class="hljs-comment">--&#x6539;&#x53D8; &#x81EA;&#x589E;&#x5E8F;&#x5217; &#x4ECE;10000&#x5F00;&#x59CB;</span>
<span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> table_name AUTO_INCREMENT = <span class="hljs-number">10000</span> ;
</code></pre>
<h2 id="23&#x3001;&#x540C;&#x65F6;&#x5220;&#x9664;&#x4E24;&#x5F20;&#x8868;"><a name="23&#x3001;&#x540C;&#x65F6;&#x5220;&#x9664;&#x4E24;&#x5F20;&#x8868;" class="anchor-navigation-ex-anchor" href="#23&#x3001;&#x540C;&#x65F6;&#x5220;&#x9664;&#x4E24;&#x5F20;&#x8868;"><i class="fa fa-link" aria-hidden="true"></i></a>2.3&#x3001;&#x540C;&#x65F6;&#x5220;&#x9664;&#x4E24;&#x5F20;&#x8868;</h2>
<pre><code class="lang-sql"><span class="hljs-keyword">DELETE</span> s,d 
<span class="hljs-keyword">FROM</span> secims.<span class="hljs-string">`studyplan`</span> s , secims.<span class="hljs-string">`studyplandetail`</span> d 
<span class="hljs-keyword">WHERE</span> s.<span class="hljs-string">`planId`</span> = d.<span class="hljs-string">`planId`</span> <span class="hljs-keyword">AND</span> s.<span class="hljs-string">`planId`</span> = <span class="hljs-number">18</span> ;
</code></pre>
<p>&#x8FD9;&#x91CC;&#x6709;&#x4E2A;&#x95EE;&#x9898;&#x5C31;&#x662F;&#xFF1A;&#x6BCD;&#x8868;&#x6709;&#xFF0C;&#x5B50;&#x8868;&#x6CA1;&#x6709;&#x5BF9;&#x5E94;&#x7684;&#xFF0C;&#x5219;&#x65E0;&#x6CD5;&#x5220;&#x9664;&#x3002;</p>
<p><strong>// &#x8FD8;&#x6709;&#x4E00;&#x4E2A;&#x6BD4;&#x8F83;&#x597D;&#x7684;&#x65B9;&#x5F0F;&#x5C31;&#x662F;&#x8BBE;&#x7F6E;&#x5916;&#x952E;&#xFF1A;</strong></p>
<p>&#x5982;&#x679C;&#x4EE5;&#x5B83;&#x8BBE;&#x7F6E;&#x4E86;&#x5916;&#x952E;&#x540E;&#xFF0C;
&#x5F53;&#x5220;&#x9664;&#x5B83;&#x4E86;&#x65F6;&#xFF0C;&#x5219;&#x53EA;&#x8981;&#x662F;&#x4EE5;&#x5B83;&#x4E3A;&#x5916;&#x952E;&#x7684;&#x90FD;&#x5C06;&#x88AB;&#x5220;&#x9664;</p>
<pre><code class="lang-sql">CONSTRAINT `planIDFK` FOREIGN KEY (`planId`) 
REFERENCES `studyplan` (`planId`) 
ON <span class="hljs-keyword">DELETE</span> <span class="hljs-keyword">CASCADE</span> 
<span class="hljs-keyword">ON</span> <span class="hljs-keyword">UPDATE</span> <span class="hljs-keyword">NO</span> <span class="hljs-keyword">ACTION</span>
</code></pre>
<p>&#x8BBE;&#x7F6E;&#x5220;&#x9664;&#x7EA7;&#x8054;&#xFF0C;&#x66F4;&#x65B0;&#x65E0;&#x64CD;&#x4F5C;&#x3002;</p>
<h2 id="24&#x3001;&#x540C;&#x65F6;&#x66F4;&#x65B0;&#x4E24;&#x5F20;&#x8868;"><a name="24&#x3001;&#x540C;&#x65F6;&#x66F4;&#x65B0;&#x4E24;&#x5F20;&#x8868;" class="anchor-navigation-ex-anchor" href="#24&#x3001;&#x540C;&#x65F6;&#x66F4;&#x65B0;&#x4E24;&#x5F20;&#x8868;"><i class="fa fa-link" aria-hidden="true"></i></a>2.4&#x3001;&#x540C;&#x65F6;&#x66F4;&#x65B0;&#x4E24;&#x5F20;&#x8868;</h2>
<p>&#x4F7F;&#x7528;&#x5185;&#x8054;&#x63A5;&#x6765;&#x5B9E;&#x73B0;&#xFF1A;</p>
<pre><code class="lang-sql">
<span class="hljs-keyword">UPDATE</span> <span class="hljs-keyword">test</span>.<span class="hljs-string">`dept`</span> d <span class="hljs-keyword">INNER</span> <span class="hljs-keyword">JOIN</span> <span class="hljs-keyword">test</span>.<span class="hljs-string">`employee`</span> e
<span class="hljs-keyword">ON</span> d.<span class="hljs-string">`deptId`</span> = e.<span class="hljs-string">`deptId`</span> 
<span class="hljs-keyword">SET</span>  d.<span class="hljs-string">`deptAddress`</span> = <span class="hljs-string">&quot;&#x6DF1;&#x5733;&quot;</span>,e.<span class="hljs-string">`empName`</span> = <span class="hljs-string">&quot;ma&quot;</span> 
<span class="hljs-keyword">WHERE</span>  d.<span class="hljs-string">`deptId`</span> = <span class="hljs-number">1</span> <span class="hljs-keyword">AND</span> e.<span class="hljs-string">`empId`</span> = <span class="hljs-number">1</span> ;
</code></pre>
<h2 id="25&#x3001;sql&#x4E2D;&#x7684;&#x4E09;&#x76EE;&#x8FD0;&#x7B97;&#x7B26;"><a name="25&#x3001;sql&#x4E2D;&#x7684;&#x4E09;&#x76EE;&#x8FD0;&#x7B97;&#x7B26;" class="anchor-navigation-ex-anchor" href="#25&#x3001;sql&#x4E2D;&#x7684;&#x4E09;&#x76EE;&#x8FD0;&#x7B97;&#x7B26;"><i class="fa fa-link" aria-hidden="true"></i></a>2.5&#x3001;SQL&#x4E2D;&#x7684;&#x4E09;&#x76EE;&#x8FD0;&#x7B97;&#x7B26;</h2>
<p>sql&#x4E2D;&#x4E5F;&#x662F;&#x652F;&#x6301;&#x4E09;&#x76EE;&#x8FD0;&#x7B97;&#x7684;,&#x8BED;&#x6CD5;&#x4E3A;:</p>
<p><strong>&#x7528;&#x6CD5;&#xFF1A;CASE  WHEN &#x6761;&#x4EF6; THEN &#x5982;&#x679C;&#x7B26;&#x5408; ELSE &#x5982;&#x679C;&#x4E0D;&#x7B26;&#x5408; END</strong></p>
<p>&#x6240;&#x4EE5;&#x5728;&#x6211;&#x4EEC;&#x8FD9;&#x4E1A;&#x52A1;&#x4E2D;&#x7684;SQL&#x8BED;&#x53E5;&#x5C31;&#x662F;:</p>
<p>&#x67E5;&#x8BE2;&#xFF1A;</p>
<pre><code class="lang-sql">
<span class="hljs-keyword">select</span>   
    <span class="hljs-keyword">CASE</span> <span class="hljs-keyword">WHEN</span> pay &gt; <span class="hljs-number">0</span> 
    <span class="hljs-keyword">THEN</span> pay * <span class="hljs-keyword">num</span> 
    <span class="hljs-keyword">ELSE</span> price * <span class="hljs-keyword">num</span> 
    <span class="hljs-keyword">END</span> <span class="hljs-keyword">as</span> amount
<span class="hljs-keyword">from</span> table_name 
<span class="hljs-keyword">order</span> <span class="hljs-keyword">by</span> amount <span class="hljs-keyword">desc</span>;
</code></pre>
<p>&#x4FEE;&#x6539;/&#x66F4;&#x65B0;&#xFF1A;</p>
<pre><code class="lang-sql"><span class="hljs-keyword">UPDATE</span> <span class="hljs-keyword">test</span>.<span class="hljs-string">`dept`</span> d 
<span class="hljs-keyword">SET</span> d.<span class="hljs-string">`deptAddress`</span> = (  
    <span class="hljs-keyword">CASE</span> <span class="hljs-keyword">WHEN</span> d.<span class="hljs-string">`deptId`</span> &gt; <span class="hljs-number">2</span> 
    <span class="hljs-keyword">THEN</span> <span class="hljs-string">&quot;ch&quot;</span> 
    <span class="hljs-keyword">ELSE</span> <span class="hljs-string">&quot;gd&quot;</span> <span class="hljs-keyword">END</span>  )  ;
</code></pre>
<h1 id="3&#x3001;&#x5E8F;&#x5217;"><a name="3&#x3001;&#x5E8F;&#x5217;" class="anchor-navigation-ex-anchor" href="#3&#x3001;&#x5E8F;&#x5217;"><i class="fa fa-link" aria-hidden="true"></i></a><strong>3&#x3001;&#x5E8F;&#x5217;</strong></h1>
<pre><code class="lang-sql">  <span class="hljs-comment">-- &#x521B;&#x5EFA;&#x5E8F;&#x5217;   </span>
  <span class="hljs-keyword">create</span> <span class="hljs-keyword">sequence</span> MYSQL.SEQ_GUI   
  <span class="hljs-keyword">start</span> <span class="hljs-keyword">with</span> <span class="hljs-number">1</span>   
  <span class="hljs-keyword">increment</span> <span class="hljs-keyword">by</span> <span class="hljs-number">1</span> ;

  <span class="hljs-comment">--&#x4E0B;&#x4E2A;&#x5E8F;&#x5217;&#xFF1A;</span>
  SEQ_GUI.NEXTVAL

  <span class="hljs-comment">--&#x5F53;&#x524D;&#x5E8F;&#x5217;&#xFF1A;</span>
  SEQ_GUI.CURRVAL

  <span class="hljs-comment">--&#x83B7;&#x53D6;&#x5E8F;&#x5217;&#xFF1A; -- oracle</span>
  <span class="hljs-keyword">select</span> SEQ_GUI.<span class="hljs-keyword">NEXTVAL</span> <span class="hljs-keyword">FROM</span> dual ;
</code></pre>
<footer class="page-footer"><span class="copyright">Copyright @copy tianwyam 2021 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x6700;&#x540E;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2020-07-26 16:51:30
</span></footer>
                                
                                </section>
                            
                        </div>
                    </div>
                
            </div>

            
                
                <a href="../distributed/sharding-jdbc.html" class="navigation navigation-prev " aria-label="Previous page: 【分布式】sharding-jdbc实现分库分表">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../redis/redis_study_notes.html" class="navigation navigation-next " aria-label="Next page: redis学习笔记">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"SQL常用使用","level":"17.1","depth":1,"next":{"title":"redis学习笔记","level":"18.1","depth":1,"path":"redis/redis_study_notes.md","ref":"redis/redis_study_notes.md","articles":[]},"previous":{"title":"【分布式】sharding-jdbc实现分库分表","level":"16.1","depth":1,"path":"distributed/sharding-jdbc.md","ref":"distributed/sharding-jdbc.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-search","-sharing","github","tbfed-pagefooter","splitter","pageview-count","anchor-navigation-ex","chapter-fold","expandable-chapters-small","livereload"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright @copy tianwyam 2021","modify_label":"最后修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"chapter-fold":{},"github":{"url":"https://github.com/tianwyam"},"livereload":{},"splitter":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":false,"showLevel":false},"pageview-count":{},"expandable-chapters-small":{},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"tianwyam","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"JAVA学习积累","links":{"sidebar":{"博客Blog":"https://blog.csdn.net/mybook201314"}},"gitbook":"*","description":"积累Java学习过程中的知识点，俗话说：好记性不如烂笔头"},"file":{"path":"SQL/sql.md","mtime":"2020-07-26T08:51:30.687Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-11-03T12:24:01.188Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-pageview-count/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

